home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / tools / rtn / getfiletype < prev    next >
Text File  |  1999-04-29  |  6KB  |  251 lines

  1. G4C
  2.  
  3. ; GetFileType
  4. ; Created by dck, extended by Brian Jones
  5. ; -------------------------------------------------------------
  6. ; This routine tries to recognise the type of a given file.
  7. ; When it returns, $$RET.0 will contain the type of file that
  8. ; "FileName" was, or "NONE" if there was no file, or "UNKNOWN"
  9. ; if the file was not one of the various filetypes defined
  10. ; below (to which you can easily add..)
  11. ; -------------------------------------------------------------
  12.  
  13. xONLOAD filename
  14. guiopen GetFileType $filename
  15.  
  16. xONRELOAD filename
  17. guiopen GetFileType $filename
  18.  
  19. xONOPEN filename    ; this is the main routine
  20. if $filename = ''
  21.    return 'NONE'
  22. endif
  23.  
  24. ; -------------------------------------------------------------
  25. ; First we check the Header - We do this in a subroutine
  26. ; because we want to set deeptrans on again before we return
  27. ; -------------------------------------------------------------
  28.  
  29. GOSUB getfiletype Check_Header ; check header (end of this file)
  30. type = $$ret.0                 ; store the file type
  31. set deeptrans on
  32.  
  33. if $type != UNKNOWN      ; did we find it ?
  34.     return $getfiletype/type  ; yes - return *full* variable path
  35. endif
  36.  
  37. ; otherwise, continue with checking file extension
  38.  
  39. extract filename ext rtn.ext  ; get extension
  40.  
  41. if $rtn.ext != ""
  42.  docase $rtn.ext
  43.   case   == ".info"
  44.        return INFO
  45.  
  46.   case   == ".txt"
  47.   case   == ".doc"
  48.   case   == ".readme"
  49.   case   == ".man"
  50.        return TEXT
  51.  
  52.   case   == ".guide"
  53.        return GUIDE
  54.  
  55.   case   == ".ilbm"
  56.   case   == ".24"
  57.   case   == ".iff"
  58.        return ILBM
  59.  
  60.   case   == ".gif"
  61.        return GIF
  62.  
  63.   case   == ".tga"
  64.        return TGA   ; or GFX or DT
  65.  
  66.   case   == ".ppm"
  67.        return PPM   ; or DT if you've got the V43 picture.datatype and the new ppm datatype
  68.  
  69.   case   == ".bmp"  ;
  70.   case   == ".pcx"  ;  the return for these could be GFX or DT
  71.   case   == ".pbm"  ;  as there are datatypes for all of them
  72.   case   == ".pgm"  ; 
  73.   case   == ".png"  ; 
  74.   case   == ".tiff" 
  75.        return GFX   ;  DT - take your pick
  76.  
  77.   case   == ".qrt"  ; qrt could go under GFX or DT but its datatype interferes with the system so I put it here
  78.   case   == ".sgi"  ; the only program that I have (or trust for .qrt) to 
  79.   case   == ".vmem" ; open these is ImageStudio so I  put these here.
  80.        return GFXED
  81.  
  82.   case   == ".font"
  83.        return FONT
  84.  
  85.   case   == ".qt"
  86.   case   == ".mov"
  87.        return QT
  88.  
  89.   case   == ".anim"
  90.        return ANIM
  91.  
  92.   case   == ".S3M"
  93.   case   == ".mod"
  94.   case   == ".XM"
  95.   case   == ".med"
  96.   case   == ".ocss"
  97.   case   == ".digi"
  98.   case   == ".tune"
  99.        return MOD
  100.  
  101.   case   == ".8svx"
  102.   case   == ".16vx"
  103.   case   == ".wav"
  104.   case   == ".aiff"
  105.   case   == ".au"
  106.   case   == ".snd"
  107.        return SMPL
  108.  
  109.   case   == ".lha"
  110.   case   == ".lzh"
  111.        return LHA
  112.  
  113.   case   == ".lzx"
  114.        return LZX
  115.  
  116.   case   == ".html"
  117.   case   == ".htm"
  118.   case   == ".index"
  119.        return HTML
  120.  
  121.   case   == ".fli"
  122.   case   == ".flc"
  123.        return FLC
  124.  
  125.   case   == ".mpg"
  126.   case   == ".mpeg"
  127.        return MPG
  128.  
  129.   case   == ".avi"
  130.        return AVI
  131.  endcase
  132. endif
  133.  
  134. ; still haven't found it..
  135.  
  136. extract filename file rtn.temp          ; see if it's a module
  137. cutvar  rtn.temp copy char 4 rtn.mod
  138. if $rtn.mod == mod.
  139.    return MOD
  140. endif
  141.  
  142. set deeptrans off
  143. if $header S= "##########"    ; a text file (probably)
  144.     set deeptrans on
  145.     return TEXT
  146. endif
  147.  
  148. set deeptrans on
  149. return UNKNOWN           ; end of GetFileType - nothing found..
  150.  
  151.  
  152. ; -------------------------------------------------------------
  153. ; This routine checks the filetype by comparing the file header.
  154. ; To do this faster than with H=, we use the ReadVar command.
  155. ; Note that we have to turn off DEEPTRANS so that we don't have 
  156. ; translation of the header since it may contain $ characters 
  157. ; which would confuse the hell out of it.
  158. ; -------------------------------------------------------------
  159.  
  160. xROUTINE Check_Header
  161.  
  162. readvar $filename 0 100 header     ; read the header
  163. set deeptrans off
  164.  
  165. if $header S= "XPKF"                 ; advance header behind an
  166.     cutvar header cut char 16 temp   ; XPK'd files xpk header.
  167. endif
  168.  
  169. docase $header
  170. case   S= "G4C"          ; Yes.. you guessed it.
  171.        return G4C
  172.  
  173. case   S= "@D"           ; Amigaguide (probably)
  174. case   S= "@d"
  175.        return GUIDE
  176.  
  177. case   S= "ã"           ; icon
  178.        return INFO
  179.  
  180. case   S= "FORM????ILBM" ; ILBM
  181. case   S= "FORM???ILBM"
  182. case   S= "FORM??ILBM"
  183.        return ILBM
  184.  
  185. case   S= "GIF"          ; GIF
  186.        return GIF
  187.  
  188. case   S= "??????JFIF"   ; JPEG
  189. case   S= "ÿØÿÄ"         ; JPEG
  190.        return JPG
  191.  
  192. case   S= "?PNG"         ; PNG
  193.        return PNG
  194.  
  195. case   S= "P4"           ; PBM
  196. case   S= "P5"           ; PGM
  197. case   S= "BM"           ; BMP
  198. case   S= "MM"           ; TIFF - I'm not entirely sure about this since I have only one TIFF writer
  199.        return GFX        ; again or DT
  200.  
  201. case   S= "P6"           ; PPM
  202.        return PPM
  203.  
  204. case   S= "FORM????DEEP" ; IFF-Deep
  205. case   S= "??VMEM"       ; ImageStudio VMEM and header
  206.        return GFXED      ; ImageStudio is all I know that will handle these
  207.  
  208. case   S= "FORM????ANIM" ; Animation
  209. case   S= "FORM???ANIM"
  210.        return ANIM
  211.  
  212. case   S= "????mdat"     ; QuickTime animation
  213.        return QT
  214.  
  215. case   S= "MMD"                 ; MED
  216. case   S= "Extended Module:"    ; XM
  217. case   S= "????????????????????????????????????????????SCRM"   ; S3M Scream Tracker 3
  218. case   S= "?????????????????????????????????????????????@"     ; Hope it's not a guide
  219. case   S= "DIGI Booster"
  220.        return MOD
  221.  
  222. case   S= "FORM????8SVX" ; 8svx Sound sample
  223.        return 8SVX     ; try gcsound - otherwise SMPL
  224.  
  225. case   S= "FORM????16VX" ; 16vx Sound sample
  226. case   S= "FORM????AIFF" ; AIFF Sound sample
  227. case   S= "RIFF????WAVE" ; Wav Sound sample
  228. case   S= ".snd"         ; .au Sound sample (I think, I've only got one)
  229.        return SMPL
  230.  
  231. case   S= "PP"           ; PowerPacked file
  232.        return PP
  233.  
  234. case   S= "??-lh"        ; LhA
  235.        return LHA
  236.  
  237. case   S= "LZX"          ; LZX
  238.        return LZX
  239.  
  240. case   S= "ZOO ?.??"     ; zoo
  241.        return ZOO
  242.  
  243. case   S= "PK"           ; unzip
  244.        return ZIP
  245.  
  246. case   S= "%%%ó%"        ; executable
  247.        return EXE
  248. endcase
  249.  
  250. return UNKNOWN
  251.